/*
 * test_msgcoder.cpp
 *
 *  Created on: Jan 13, 2014
 *      Author: killerg
 */


#include "share/msg_coder.h"
#include "share/util.h"

#include <string>
#include <assert.h>

bool test_msgcoder() {
    init_code_table();

    size_t maxsize = 100000;
    char buffer[maxsize];
    for (size_t i=0; i<maxsize; ++i) {
        buffer[i] = i % 26 + 'a';
    }


    for (size_t j=0; j<maxsize; ++j) {
        for (int i=0; i<10000; ++i) {

    //        printf("------------------------------------------\n");
            size_t buffer_len = 10000;
            std::string src = hex_to_cstr((uint8_t*)buffer, buffer_len);
    //        printf("src: %s\n", src.c_str());
            encmsg(i, (uint8_t*)buffer, buffer_len);
            std::string enc = hex_to_cstr((uint8_t*)buffer, buffer_len);
    //        printf("enc: %s\n", enc.c_str());
            encmsg(i, (uint8_t*)buffer, buffer_len);
            std::string dec = hex_to_cstr((uint8_t*)buffer, buffer_len);
    //        printf("dec: %s\n", dec.c_str());

            assert(dec == src);
        }
    }

    destroy_code_table();

    return true;
}
